#ifndef PLAYER_FEATURE_H
#define PLAYER_FEATURE_H

#include "feature.h"

#include "../widgets/cool_label.h"
#include "../widgets/clickable_label.h"
#include "../widgets/checkbox.h"
#include "../widgets/ps_slider.h"
#include "../widgets/player_controls.h"
#include "../widgets/gui_frame.h"
#include "../widgets/textbox.h"
#include "../widgets/list.h"

#include "../../model/player.h"

class PlayerFeature: public Feature,
                     private AnimationObserver,
                     private PlayerListener,
                     private SliderListener,
                     private PlayerControlsListener,
                     private CheckBoxListener,
                     private ClickableLabelListener,
                     private ListListener
{
public:
    PlayerFeature(int _id, Engine* _engine, int _x, int _y, int _w, int _h,
                  ControllerProxy* _cProxy, MainWidget* _mw);
    virtual ~PlayerFeature();

protected:

    virtual void Hide( void );
    virtual void doShow( void );
    virtual void doHide( void );

    virtual void Paint( QPainter &painter );

private:

    // fields -----------
    Song* song;
    Player* player;
    bool updateSlider;

    // pens and brushes
    QBrush* invisibleBrush;

    // widgets
    GuiFrame* songInfoFrame;
    Label* songNameFixedLabel;
    CoolLabel* songNameLabel;
    Label* songLengthFixedLabel;
    CoolLabel* songLengthLabel;

    GuiFrame* segmentsFrame;

    GuiFrame* segmentInfoFrame;
    Label* sFixedInPlay;
    CoolLabel* sInPlay;
    CheckBox* sEnabled;
    Label* sFixedStart;
    CoolLabel* sStart;
    Label* sFixedEnd;
    CoolLabel* sEnd;
    Label* sFixedLength;
    CoolLabel* sLength;
    Slider* sSlider;
    GuiFrame* sTimeFrame;
    Label* stMainTime;
    Label* stZZZLabel;
    Label* sFixedSpeed;
    CoolLabel* sSpeed;
    Slider* sSpeedSlider;
    Label* sFixedPitch;
    CoolLabel* sPitch;
    Slider* sPitchSlider;
    CheckBox* sLoopBox;

    GuiFrame* segmentsActionFrame;
    ClickableLabel* sEnableAll;
    ClickableLabel* sDisableAll;
    ClickableLabel* sEdit;
    ClickableLabel* sSave;

    GuiFrame* playerFrame;
    PSSlider* playerSlider;
    PlayerControls* controls;
    GuiFrame* pTimeFrame;
    Label* pTime;
    Label* pZZZTime;
    GuiFrame* pSpeedFrame;
    Label* pSpeed;
    Label* pFixedSpeed;

    GuiFrame* loopsFrame;
    List* loopsList;
    GuiFrame* lInfoFrame;
    Label* lFixedName;
    CoolLabel* lName;
    CheckBox* lEnabled;
    Label* lFixedStart;
    CoolLabel* lStart;
    Label* lFixedEnd;
    CoolLabel* lEnd;
    PSSlider* lSlider;

    GuiFrame* lActionsFrame;
    ClickableLabel* lEnableAll;
    ClickableLabel* lDisableAll;
    ClickableLabel* lEdit;
    ClickableLabel* lSave;

    // functions --------

    // AnimationObserver implementation
    virtual void OnPause    ( Animation* a );
    virtual void OnStop     ( Animation* a );
    virtual void OnEnd      ( Animation* a );
    virtual void OnPlay     ( Animation* a );

    // PlayerListener implementation
    virtual void OnSegmentChange( int newSegment );

    // SliderListener implementation
    virtual void OnPosChanged( Slider* sender, double newPos );
    virtual void OnClickOrOnEndDrag( Slider* sender, double newPos );
    virtual void OnStartDrag( Slider* slider );

    // PlayerControlsListener implementation
    virtual void OnControlClick( PlayerControls* sender, int controlId );
    virtual void OnVolumeChange( PlayerControls* sender, float vol );

    // CheckBoxListener implementation
    virtual void OnCheckChange( CheckBox* sender, bool checked );

    // ClickableLabelListener implementation
    virtual void OnClick( ClickableLabel* sender );

    // ListListener implementation
    virtual void OnSelect(List* sender, int index);
    virtual void OnDoubleClick(List* sender, int index);

    // others
    void InitializeFlagsAndValues( void );

    void BuildPensAndBrushes( void );
    void DeletePensAndBrushes( void );

    void BuildWidgets( void );

    void BuildAnimations( void );
    void DeleteAnimations( void );

    void Load( void );
    void Unload( void );
    void DisableWidgets( void );
};

#endif // PLAYER_FEATURE_H
